home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / cl5426.asm < prev    next >
Assembly Source File  |  1993-12-06  |  12KB  |  386 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file CL5426.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1993 Hartmut Schirmer, Feldstr. 118, 2300 Kiel 1, Germany
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17. ;
  18. ; This driver supports Cirrus CL-GD542X Chipsets
  19. ; Check your BIOS documentation if all of below modes are supported !
  20. ;
  21. ; This is basically Hartmut's cirrus54 driver modified by Csaba Biegl.
  22. ; Changes:
  23. ;    1. Added 1280x1024 16 color mode
  24. ;    2. Changed 256 color modes to use fast scan line fills.
  25. ;
  26. include grdriver.inc
  27. cseg    segment byte public 'code'
  28.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  29.  
  30.  
  31. ;--------------------------------------------------------------------------
  32. ; DRIVER HEADER
  33. ;  The following entries MUST match the structure and constant
  34. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  35. ;  The mode word should contain the following bitfields:
  36. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  37. ;     - the adapter type field should be specified
  38. ;     - the memory size field should be specified
  39. ;     - the paging mode field should be specified
  40. ;  The mode set routine will OR in the plane bitfield as it will
  41. ;  change when different color number modes are requested.
  42. ;--------------------------------------------------------------------------
  43.  
  44.     dw    offset mode_set_routine
  45.     dw    offset paging_routine
  46. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_NO_RW
  47. ;
  48. ; The 'def_xx' fields are filled in by go32 from the corresponding
  49. ; fields of the 'GO32' environment variable
  50. ;
  51. def_tw  dw    80        ; text width
  52. def_th  dw    25        ; text height
  53. def_gw  dw    640        ; graphics width
  54. def_gh  dw    480        ; graphics height
  55. def_nc  dw    16        ; graphics colors
  56.     dw    offset driver_init_routine
  57.     dw    offset text_mode_table
  58.     dw    offset graphics_mode_table
  59.  
  60. ;
  61. ; Biggest text and graphics sizes
  62. ;
  63. Max_TW  equ    132
  64. Max_TH  equ    50
  65. Max_GWn equ    800        ; non interlaced!!!
  66. Max_GHn equ    600
  67. Max_GW  equ    1024        ; may be interlaced
  68. Max_GH  equ    768
  69.  
  70.  
  71. ;--------------------------------------------------------------------------
  72. ; TABLE OF SUPPORTED TEXT MODES
  73. ;    - keep sorted by size
  74. ;    - end with an all 0 entry
  75. ;    - BIOS field = 0xff disables it
  76. ;    - fields:
  77. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  78. ;--------------------------------------------------------------------------
  79. text_mode_table        label word
  80.     dw    80,    25,    2,    007h +  00000h
  81.     dw    40,    25,    16,    001h +  00000h
  82.     dw    80,    25,    16,    003h +  00000h
  83.     dw    80,    50,    16,    003h +  00100h
  84.     dw    132,    25,    16,    014h +  00000h
  85.     dw    132,    43,    16,    054h +  00000h
  86.     dw    0,    0,    0,    000h +  00000h
  87.  
  88.  
  89. ;--------------------------------------------------------------------------
  90. ; TABLE OF SUPPORTED GRAPHICS MODES
  91. ;    - keep sorted first by colors then by size
  92. ;    - end with an all 0 entry
  93. ;    - BIOS field = 0xff disables it
  94. ;    - fields:
  95. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  96. ;--------------------------------------------------------------------------
  97. graphics_mode_table    label word
  98.     dw    320,    200,    16,    00dh +  00000h
  99.     dw    640,    200,    16,    00eh +  00000h
  100.     dw    640,    350,    16,    010h +  00000h
  101.     dw    640,    480,    16,    012h +  00000h
  102.     dw    800,    600,    16,    058h +  00000h
  103.     dw    1024,    768,    16,    05dh +  00000h
  104.     dw    1280,  1024,    16,    06ch +  00000h
  105.     dw    320,    200,    256,    013h +  00000h
  106.     dw    640,    480,    256,    05fh +  00000h
  107.     dw    800,    600,    256,    05ch +  00000h
  108.     dw    1024,    768,    256,    060h +  00000h
  109.     dw    640,    480,  32768,    066h +  00000h
  110.     dw    800,    600,  32768,    067h +  00000h
  111.     dw    0,      0,      0,    000h +  00000h
  112.  
  113.  
  114. ;--------------------------------------------------------------------------
  115. ; TABLE OF SPECIAL SETUP PROCEDURES
  116. ;  You may need such procedures for:
  117. ;     -- reloading fonts on standard EGA or VGA for
  118. ;     higher resolution text modes
  119. ;     -- enable HiColor mode of some Super VGAs
  120. ;     -- Handle the parameter passing conventions of the VESA BIOS
  121. ;     -- put VGA into 256 color plane mode ("MODE X")
  122. ;     -- etc...
  123. ;  There should be one entry in the table for every non-zero
  124. ;  'setup_procedure_index' in the text and graphics mode tables.
  125. ;  The first entry in the table belongs to index 100h, and so on.
  126. ;  The special setup procedure is invoked via a near call.
  127. ;
  128. ;  Entry: DI=address of the mode record from the text or graphics
  129. ;      table to set up.
  130. ;
  131. ;  Exit:  Adapter configured
  132. ;      BX=driver mode word as it should be returned by the mode set
  133. ;         routine. Typically it involves picking up the mode word
  134. ;         from the header and OR-ing in the appropriate bitplane mode
  135. ;         bitfield. (This is not needed for text modes)
  136. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  137. ;
  138. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  139. ;--------------------------------------------------------------------------
  140. special_setup_table    label word
  141.     dw    offset  VGA_50row_mode_set
  142.  
  143. ;
  144. ; Routine to set up VGA 50 row mode
  145. ; interface is described above
  146. ;
  147. VGA_50row_mode_set    proc    near
  148.     mov    ax,03h            ; set 80x25 mode
  149.     int    10h
  150.     xor    bx,bx
  151.     mov    ax,1112h        ; load 8x8 font
  152.     int    10h
  153.     ret
  154. VGA_50row_mode_set    endp
  155.  
  156.  
  157. ;--------------------------------------------------------------------------
  158. ; DRIVER INIT ROUTINE
  159. ;  called once after the driver is loaded
  160. ;  may do one or more of the followings:
  161. ;    - check for proper board type
  162. ;    - check amount of RAM on board, and:
  163. ;    -- update word in header to reflect correct amount
  164. ;    -- disable modes in the tables for which there is not enough RAM
  165. ;    - check for special equipment (HiColor DAC, etc...)
  166. ;
  167. ;  Entry: nothing
  168. ;
  169. ;  Exit:  AX=status:
  170. ;       non-zero: OK,
  171. ;       0: something went wrong (e.g. wrong adapter, etc..)
  172. ;      BX,CX,DX may be trashed
  173. ;
  174. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  175. ;--------------------------------------------------------------------------
  176. driver_init_routine    proc    far
  177.     mov    ax,1            ; Really primitive, but works
  178.     ret                ; Make sure you've an GD542X Chip !
  179. driver_init_routine    endp
  180.  
  181.  
  182. ;--------------------------------------------------------------------------
  183. ; MODE SET ROUTINE
  184. ;  sets up a text or graphics mode as close as possible to the one
  185. ;  reguested by the user with regard to number of colors and size.
  186. ;
  187. ;  Entry: AX=mode selection
  188. ;     0 = 80x25 text
  189. ;     1 = default text
  190. ;     2 = text CX cols by DX rows
  191. ;     3 = biggest text
  192. ;     4 = 320x200 graphics
  193. ;     5 = default graphics
  194. ;     6 = graphics CX width by DX height
  195. ;     7 = biggest non-interlaced graphics
  196. ;     8 = biggest graphics
  197. ;     9 = graphics BX colors, CX width by DX height
  198. ;
  199. ;  Exit: BX=driver mode flag
  200. ;     CX=width (in pixels or characters)
  201. ;     DX=height
  202. ;
  203. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  204. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  205. ;     MUCH TABLE DRIVEN
  206. ;--------------------------------------------------------------------------
  207. mode_set_routine    proc    far
  208.     push    ds
  209.     push    di
  210.     push    si
  211.     mov    si,cs
  212.     mov    ds,si
  213.     cmp    ax,9
  214.     jbe    DoIt
  215.     jmp    Exit
  216. DoIt:    add    ax,ax
  217.     mov    si,ax
  218.     jmp    WORD PTR mode_set_table[si]
  219. mode_set_table  label    word
  220.     dw    offset mode_0
  221.     dw    offset mode_1
  222.     dw    offset mode_2
  223.     dw    offset mode_3
  224.     dw    offset mode_4
  225.     dw    offset mode_5
  226.     dw    offset mode_6
  227.     dw    offset mode_7
  228.     dw    offset mode_8
  229.     dw    offset mode_9
  230. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  231.     mov    bx,def_nc
  232.     mov    cx,80
  233.     mov    dx,25
  234.     jmp    Lookup
  235. mode_1: mov    si,offset text_mode_table    ; default text
  236.     mov    bx,def_nc
  237.     mov    cx,def_tw
  238.     mov    dx,def_th
  239.     jmp    Lookup
  240. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  241.     mov    bx,def_nc
  242.     jmp    Lookup
  243. mode_3: mov    si,offset text_mode_table    ; biggest text
  244.     mov    bx,def_nc
  245.     mov    cx,Max_TW
  246.     mov    dx,Max_TH
  247.     jmp    Lookup
  248. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  249.     mov    bx,def_nc
  250.     mov    cx,320
  251.     mov    dx,200
  252.     jmp    Lookup
  253. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  254.     mov    bx,def_nc
  255.     mov    cx,def_gw
  256.     mov    dx,def_gh
  257.     jmp    Lookup
  258. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  259.     mov    bx,def_nc
  260.     jmp    Lookup
  261. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  262.     mov    bx,def_nc
  263.     mov    cx,Max_GWn
  264.     mov    dx,Max_GHn
  265.     jmp    Lookup
  266. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  267.     mov    bx,def_nc
  268.     mov    cx,Max_GW
  269.     mov    dx,Max_GH
  270.     jmp    Lookup
  271. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  272. ;
  273. ; At this point:
  274. ;   SI points to the table to search (text or graphics)
  275. ;   BX has colors
  276. ;   CX has width
  277. ;   DX has height
  278. ;
  279. Lookup: xor    ax,ax                ; last color number seen
  280. Find_C: cmp    [si+4],ax            ; last color number == this?
  281.     je    Same_C
  282.     jb    Prev_C                ; end of table -- use last color
  283.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  284.     je    Prev_C                ; not -- use last color
  285.     mov    ax,[si+4]            ; record color number
  286.     mov    di,si                ; start of entries w/ this color
  287.     cmp    ax,bx                ; enough colors ?
  288.     jae    Find_S
  289. Same_C: add    si,8
  290.     jmp    Find_C
  291. Prev_C: or    ax,ax                ; found any color at all?
  292.     je    Exit
  293. ;
  294. ; At this point:
  295. ;   DI points into the table to the first entry with the desired color
  296. ;      number (either it has enough colors or it is the highest color
  297. ;      number supported by the driver). Additionally, at least the
  298. ;      first (= smallest size) entry for this color is valid (has a
  299. ;      valid BIOS number).
  300. ;   AX has the color number adjusted for the driver
  301. ;   CX has width
  302. ;   DX has height
  303. ;
  304. Find_S: cmp    [di+4],ax            ; still the same color #?
  305.     jne    Prev_S
  306.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  307.     je    Prev_S
  308.     cmp    [di],cx
  309.     jb    Next_S
  310.     cmp    [di+2],dx
  311.     jae    GotIt
  312. Next_S: add    di,8
  313.     jmp    Find_S
  314. Prev_S: sub    di,8
  315. ;
  316. ; At this point:
  317. ;   DI points to the table entry we want to set up
  318. ;
  319. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  320.     or    ah,ah                ; special ?
  321.     je    doBIOS
  322.     mov    al,ah
  323.     xor    ah,ah
  324.     dec    ax
  325.     add    ax,ax
  326.     mov    si,ax
  327.     call    WORD PTR special_setup_table[si]
  328.     jmp    RetVal
  329. doBIOS: int    10h
  330.     mov    bx,GRD_1_PLANE
  331.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  332.     je    doFLAG
  333.     mov    bx,GRD_4_PLANES
  334.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  335.     je    doFLAG
  336.     mov    bx,GRD_8_F_PLANES
  337.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  338.     je    doFLAG
  339.     mov    bx,GRD_16_PLANES
  340.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  341.     je    doFLAG
  342.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  343. doFLAG: or    bx,mode_W
  344. RetVal: mov    cx,[di]
  345.     mov    dx,[di+2]
  346. Exit:    pop    si
  347.     pop    di
  348.     pop    ds
  349.     ret
  350. mode_set_routine    endp
  351.  
  352.  
  353. ;--------------------------------------------------------------------------
  354. ; PAGING ROUTINE
  355. ;
  356. ;  Entry: AH=read page
  357. ;      AL=write page
  358. ;
  359. ;  Exit: VGA configured.
  360. ;     AX,BX,CX,DX,SI,DI may be trashed
  361. ;
  362. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  363. ;     This code must be relocatable and may not reference any data!
  364. ;--------------------------------------------------------------------------
  365.     assume  ds:nothing, es:nothing
  366.  
  367. paging_routine  proc    far
  368.     .286
  369.     shl    ah,4
  370.     mov    dx,03ceh
  371.     mov    al,9
  372.     out    dx,al
  373.     inc    dx
  374.     mov    al,ah
  375.     out    dx,al
  376.  
  377.     mov    al,8        ; reconfig GR CTRL port for mask writes
  378.     dec    dx
  379.     out    dx,al
  380.     ret
  381. paging_routine  endp
  382.  
  383.  
  384. cseg    ends
  385.     end
  386.